package com.jianfeiliao.portfolio.page;

import com.jianfeiliao.portfolio.panel.header.HeaderPanel;
import com.jianfeiliao.portfolio.panel.footer.FooterPanel;
import com.jianfeiliao.portfolio.panel.splash.SplashPanel;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class BasePage extends WebPage {
    
    private static final long serialVersionUID = 1L;
    private static final String hostName = "jianfeiliao.com";
    private Label pageTitle;
    
    public BasePage(final PageParameters params) {
        super(params);        
        setVersioned(false);

        pageTitle = new Label("pagetitle", hostName);
        add(pageTitle);
        
        add(new HeaderPanel("header"));
        add(new FooterPanel("footer"));
        add(new SplashPanel("splash", this));

        // add css style class base on the page
        final String styleName = this.getClass().getSimpleName().toLowerCase();
        add(new WebMarkupContainer("body"){

            @Override
            public boolean isTransparentResolver() {
                return true;
            }

            @Override
            protected void onComponentTag(ComponentTag tag) {
                tag.put("class",  styleName);
            }
        });

//        add(new WebMarkupContainer("body").
//                add(new AttributeModifier("class", true, new Model<String>(styleName))));
    }

    protected void setPageTitle(String title) {
        pageTitle.setDefaultModelObject(hostName + " - " + title);
    }

    public String getPageTitle() {
        return pageTitle.getDefaultModelObjectAsString();
    }
}
